This patch adds a forward lookup of any hostnames listed in the
"hosts allow" or "hosts deny" daemon config options.  Based on
a patch by Paul Williamson.

To use this patch, run these commands for a successful build:

    patch -p1 <patches/daemon-forward-lookup.diff
    ./configure                         (optional if already run)
    make

based-on: 1ddcdaf3f6808ba53aef9e19f630a18808de22ac
diff --git a/access.c b/access.c
--- a/access.c
+++ b/access.c
@@ -210,6 +210,42 @@ static int match_address(char *addr, char *tok)
 	return ret;
 }
 
+static int match_hostlookup(char *addr, char *tok)
+{
+	struct hostent *hp = NULL;
+	unsigned int i, len;
+	char *p;
+
+	if ((p = strchr(tok,'/')) != NULL) {
+		*p = '\0';
+		len = p - tok;
+	} else
+		len = strlen(tok);
+
+	/* Fail quietly (hp left NULL) if tok is an address, not a hostname. */
+#ifdef INET6
+	if (strchr(tok, ':') != NULL) {
+		;
+	} else
+#endif
+	if (strspn(tok, ".0123456789") != len)
+		hp = gethostbyname(tok);
+
+	if (p)
+		*p = '/';
+
+	if (!hp)
+		return 0;
+
+	for (i = 0; hp->h_addr_list[i] != NULL; i++) {
+		tok = inet_ntoa(*(struct in_addr*)(hp->h_addr_list[i]));
+		if (match_address(addr, tok))
+			return 1;
+	}
+
+	return 0;
+}
+
 static int access_match(char *list, char *addr, char *host)
 {
 	char *tok;
@@ -223,7 +259,7 @@ static int access_match(char *list, char *addr, char *host)
 		strlower(host);
 
 	for (tok = strtok(list2, " ,\t"); tok; tok = strtok(NULL, " ,\t")) {
-		if (match_hostname(host, tok) || match_address(addr, tok)) {
+		if (match_hostname(host, tok) || match_address(addr, tok) || match_hostlookup(addr, tok)) {
 			free(list2);
 			return 1;
 		}
